package com.zx.order.Controller;

import com.zx.order.Services.OrderService;
import com.zx.order.entity.Order;
import com.zx.order.properties.orderProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

//@RefreshScope//当nacos配置中心配置发生改变时，会自动更新到服务中
@RestController
@RequestMapping("/orders")
public class OrderController {

    @Autowired
    private OrderService orderService;



//    @Value("${order.timeout}")
//    private String timeout;
//    @Value("${order.auto-confirm}")
//    private String autoConfirm;

    @Autowired
    private orderProperties orderProperties;
    @GetMapping("/orderConfig")
    public String orderConfig(){
        return "timeout:"+orderProperties.getTimeout()+"   autoConfirm:"+orderProperties.getAutoConfirm() +"   dbUrl:"+orderProperties.getDbUrl();
    }

    @GetMapping("/createOrder")
    public Order  getOrderById(@RequestParam Long productId, @RequestParam Long userId){
        Order order =  orderService.createOrder(productId,userId);
        return order;
    }
}
